//添加内容
var addhtml=''
addhtml+='<div class="form-div"><form id="fomr">';
addhtml+='<div class="layui-form-item"><label class="layui-form-label">标题</label><div class="layui-input-block"><input type="text" name="title" autocomplete="off" placeholder="请输入公告标题" class="layui-input"></div></div>';
addhtml+='<div class="layui-form-item"><label class="layui-form-label">内容</label><div class="layui-input-block"><textarea placeholder="请输入内容" class="layui-textarea" name="content" ></textarea></div></div>';
addhtml+='<input type="hidden" name="token" value="'+token+'">';
addhtml+='</form></div>';



//编辑
var edithtml=''
edithtml+='<div class="form-div"><form id="fomr">';
edithtml+='<div class="layui-form-item"><label class="layui-form-label">名称</label><div class="layui-input-block"><input type="text" name="coin_name" autocomplete="off" placeholder="请输入货币名称" class="layui-input"></div></div>';
edithtml+='<div class="layui-form-item"><label class="layui-form-label">别名</label><div class="layui-input-block"><input type="text" name="tag" autocomplete="off" placeholder="请输入货币别名" class="layui-input"></div></div>';
edithtml+='<input type="hidden" name="id">';
edithtml+='<input type="hidden" name="token" value="'+token+'">';
edithtml+='</form></div>';



layui.use('table', function() {
	var table = layui.table;
	
	var $ = layui.$, active = {
		//添加公告
	 	add: function(){
	      layer.open({
			  type: 1,
			  title:"新增公告",
			  area: ['800px', '300px'], //宽高
			  maxmin: true,
			  resize:true,
			  content: addhtml,
			  btn: ['提交', '关闭'],
			  btn1: function(){
			  	var Adata=$("#fomr").serialize();
			    $.ajax({
			    	type:'post',
			    	dataType:'json',
			    	url:addSrc,
			    	data:Adata,
			    	success:function(data){
			    		var code=data.code;
			    		var msg=data.msg;
			    		if(code==1){
			    			layer.close(layer.index)
			    			layer.alert(msg,{icon: 1},function(){
			    				location.reload();
			    			})
			    		}else{
			    			layer.alert(msg,{icon: 5})
			    		}
			    	}
			    })
			  }
			});
	    }
	 }
	 $('.right-center .right-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	});
	
	
    layer.msg('数据加载中...', {
		icon: 16,
		shade: 0.3,
		success: function() {
			table.render({
				elem: '#centet-cen',
				url: listSrc,
				height: $(".center-tab").height(),
				id:'idTest',
				response: {
		  			statusCode: 1, //成功的状态码，默认：0
				},          
				page:true,
				cols: [
					[ //标题栏
						{
							field: 'id',
							title: 'ID',
							width: 60
						}, {
							field: 'title',
							title: '标题',
							width: 300
						}, {
							field: 'username',
							title: '发布人',
							width: 100
						}, {
							field: 'content',
							title: '内容'
						}, {
							field: 'create_date',
							title: '发布时间',
							width: 200
						}, {
							field: 'oper',
							title: '操作',
							width: 160,
							toolbar: '#barDemo'
						}

					]
				],
				limit: 10
			});
			layer.close(layer.index);
			
		}
	})
    
    
    table.on('tool(table)', function(obj) {
    	
    	var data = obj.data;
    	
    	if(obj.event === 'see') {
    		var id=data.id;
    		var title = data.title;
    		layer.open({
    			type: 2,
    			title: title,
    			shadeClose: true,
    			shade: 0.8,
    			area: ['800px', '80%'],
    			content: ''+seeSrc+'?id='+id+''
    		});
    	}else if(obj.event === 'del'){
    		var id = data.id;
    		layer.alert('您确定要删除该公告！',{
				icon: 2,
				btn: ['确定', '关闭'],
				btn1: function(){
					$.ajax({
				    	type:'post',
				    	dataType:'json',
				    	url:delSrc,
				    	data:{
				    		token:token,
				    		id:id
				    	},
				    	success:function(data){
				    		var code=data.code;
				    		var msg=data.msg;
				    		if(code==1){
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 1},function(){
				    				location.reload();
				    			})
				    		}else{
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 5})
				    		}
				    	}
				    })
				}
			})
    	}
    	
    	
    })
})
